import os
import logging
import datetime

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

# # # 控制台输出日志
# console = logging.StreamHandler()
# logger.addHandler(console)

# 文件名字
base_dir = (os.path.dirname(os.path.abspath(__file__)))
log_dir = os.path.join(base_dir,'logs')
log_file = datetime.datetime.now().strftime("%Y-%m-%d")+".log"
log_name = log_dir + "\\" + log_file
print(log_name)



# 输出日志到文件
file_handle = logging.FileHandler(log_name)
formatter = logging.Formatter('%(asctime)s %(filename)s---> %(funcName)s %(levelno)s: %(levelname)s ----> %(message)s')
file_handle.setFormatter(formatter)
logger.addHandler(file_handle)

logger.debug('test1233')
file_handle.close()
logger.removeHandler(file_handle)